import { reqGetRecordList } from "@/api/cimrtsApi";
import { MyProjectManager } from "../MyProjectManager";
import { Destroyable, HasOwner, react, reactJson } from "earthsdk3";


export class SwitchCimrts extends HasOwner<MyProjectManager> {

    // 显示隐藏
    private _show = this.dv(react<boolean>(false));
    get show() { return this._show.value; }
    get showChanged() { return this._show.changed; }
    set show(value: boolean) { this._show.value = value; }

    // 服务路径
    private _url = this.dv(react<string>(""));
    get url() { return this._url.value; }
    get urlChanged() { return this._url.changed; }
    set url(value: string) { this._url.value = value; }

    // 服务名称
    private _name = this.dv(react<string>(""));
    get name() { return this._name.value; }
    get nameChanged() { return this._name.changed; }
    set name(value: string) { this._name.value = value; }

    // 服务列表
    private _recordLists = this.dv(reactJson<any>([]));
    get recordLists() { return this._recordLists.value; }
    get recordListsChanged() { return this._recordLists.changed; }
    set recordLists(value: any) { this._recordLists.value = value; }

    // 获取切片服务列表
    async getRecordList() {
        try {
            const param = {
                "pageNum": 1,
                "pageSize": 100000000,
            }
            const res = await reqGetRecordList(param)
            // @ts-ignore
            if (res.status != 'ok') return;
            this.recordLists = res.data.data
        } catch (error) {
            console.error(error);
        }
    }

    async init() {
        await this.getRecordList();
        this.url = this.owner.cimrtsManager.cimrtsUrl
        this.name = this.owner.cimrtsManager.eSRtsTileset.tileServiceName
    }
    clear() {
    }

    constructor(owner: MyProjectManager) {
        super(owner);
    }
}

